package com.halixun.d2app.adapter.holder;

import android.view.View;
import android.widget.TextView;

import com.halixun.d2app.R;
import com.halixun.d2app.adapter.OrderDetailAdapter;
import com.halixun.d2app.base.BaseViewHolder;
import com.halixun.d2app.bean.OrderDetais;
import com.halixun.d2app.utils.ToastUtils;

/**
 * @ProjectName: D2App
 * @Package: com.halixun.d2app.adapter.holder
 * @ClassName: OrderDetailViewHolder
 * @Description: java类作用描述
 * @Author: hdx
 * @CreateDate: 2019/12/18 14:08
 * @UpdateUser: hdx
 * @UpdateDate: 2019/12/18 14:08
 * @UpdateRemark: 更新说明：
 * @Version: 1.0
 */
public class OrderDetailViewHolder extends BaseViewHolder<OrderDetais.Item1Bean.ListBean> implements View.OnClickListener {

    private TextView xuNum, footId, orderNumber, createTime, price, tuiKuan;

    private OrderDetailAdapter.OrderDetailListener listener;

    private OrderDetais.Item1Bean.ListBean data;

    public OrderDetailViewHolder(View itemView) {
        super(itemView);
        initView();
        setListeners();
    }

    public OrderDetailViewHolder(View itemView, OrderDetailAdapter.OrderDetailListener listener) {
        this(itemView);
        this.listener = listener;
    }

    private void setListeners() {
        tuiKuan.setOnClickListener(this);
    }

    private void initView() {
        xuNum = itemView.findViewById(R.id.xuNum);
        footId = itemView.findViewById(R.id.footId);
        orderNumber = itemView.findViewById(R.id.orderNumber);
        createTime = itemView.findViewById(R.id.createTime);
        price = itemView.findViewById(R.id.price);
        tuiKuan = itemView.findViewById(R.id.tuiKuan);
    }

    @Override
    public void setLayoutInfo(OrderDetais.Item1Bean.ListBean info) {
        this.data = info;
        xuNum.setText((getAdapterPosition() + 1) + "");
        switch (info.getPayType()) {
            case 0:
            case 1:
                footId.setText("微信支付");
                break;
            case 2:
            case 3:
                footId.setText("支付宝支付");
                break;
            case 7:
                footId.setText("现金支付");
                break;
        }
        orderNumber.setText(info.getOrderId());
        createTime.setText(info.getCreateTime());
        price.setText(info.getOrderMoney() + "");
        switch (info.getOrderState()) {
            case 0:
                tuiKuan.setEnabled(false);
                tuiKuan.setClickable(false);
                tuiKuan.setText("未支付");
                break;
            case 3:
            case 1:
                tuiKuan.setEnabled(true);
                tuiKuan.setClickable(true);
                tuiKuan.setText("退款");
                break;
            case -1:
//                tuiKuan.setEnabled(false);
//                tuiKuan.setClickable(false);
//                tuiKuan.setText("订单已取消");
//                break;
            case -2:
                tuiKuan.setEnabled(false);
                tuiKuan.setClickable(false);
                tuiKuan.setText("已退款");
                break;
            default:
                break;
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tuiKuan:
                if (data.getPayType() == 7) {
                    ToastUtils.showCenterToast("现金支付无法线上退款");
                    return;
                }
                if (null != listener) {
                    listener.onOrderDetailListener(getAdapterPosition());
                }
                break;
        }
    }
}
